﻿using FineUI;
using SysManage.BLL;
using System;
using ZHDJ.Data.Models.Center;

namespace SysManage.Module.CadreWork
{
    public partial class SuggestionEdit : PageBase
    {
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            string id = GetQueryIntValue("id");
            if (id != "")
            {
                PartyCadresWorkSuggest suggest = DB.PartyCadresWorkSuggests.Find(id);
                if (suggest == null)
                {
                    // 参数错误，首先弹出Alert对话框然后关闭弹出窗口
                    Alert.Show("参数错误！", String.Empty, ActiveWindow.GetHideReference());
                    return;
                }

                txtTitle.Text = suggest.Title;
                txtUserName.Text = suggest.UserName;
                txtContactWay.Text = suggest.ContactWay;
                txtCreateTime.Text = Convert.ToDateTime(suggest.CreateTime).ToString("yyyy-MM-dd");
                txtContent.Text = suggest.Content;
                txtReply.Text = suggest.Reply;
            }
        }
        #endregion

        #region Events

        private void SaveData()
        {
            string id = GetQueryIntValue("id");
            string imageUrl = string.Empty;

            if (id != "")
            {
                //更新
                PartyCadresWorkSuggest suggest = DB.PartyCadresWorkSuggests.Find(id);
                if (suggest == null)
                {
                    Alert.Show("参数错误！", String.Empty, ActiveWindow.GetHideReference());
                    return;
                }

                suggest.Reply = txtReply.Text.Trim();
                suggest.Status = 1;
                suggest.ModifyTime = DateTime.Now;
                suggest.ModifyBy = CurrentUser.LoginID;

                DB.SaveChanges();
            }
        }

        /// <summary>
        /// 保存并关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SaveData();

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}